package com.reebake.ideal.infra.controller;

import java.util.List;

import cn.hutool.core.bean.BeanUtil;
import cn.hutool.core.util.ObjectUtil;
import cn.hutool.core.util.StrUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.reebake.ideal.mybatis.core.PageResult;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.reebake.ideal.infra.entity.ConfigParam;
import com.reebake.ideal.infra.service.ConfigParamService;
import com.reebake.ideal.infra.vo.ConfigParamQueryParamVO;
import com.reebake.ideal.infra.vo.ConfigParamVO;

 /**
 * 配置参数控制层
 */
@Tag(name = "配置参数对象功能接口")
@RestController
@RequestMapping("/config/param")
public class ConfigParamController {
    @Autowired
    private ConfigParamService configParamService;
    
    /** 
     * 分页查询
     *
     * @param queryParam 查询参数
     * @return 查询结果
     */
    @Operation(summary = "分页查询")
    @PostMapping("page")
    public PageResult<ConfigParamVO> page(@RequestBody ConfigParamQueryParamVO queryParam) {
        LambdaQueryWrapper<ConfigParam> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.like(StrUtil.isNotBlank(queryParam.getParamCode()), ConfigParam::getParamCode, queryParam.getParamCode());
        queryWrapper.like(StrUtil.isNotBlank(queryParam.getParamName()), ConfigParam::getParamName, queryParam.getParamName());
        queryWrapper.eq(StrUtil.isNotBlank(queryParam.getParamType()), ConfigParam::getParamType, queryParam.getParamType());
        queryWrapper.like(StrUtil.isNotBlank(queryParam.getParamValue()), ConfigParam::getParamValue, queryParam.getParamValue());
        
        queryParam = configParamService.page(queryParam, queryWrapper);
        
        return queryParam.to(ConfigParamVO.class);
    }
    
    /** 
     * 保存或更新数据
     *
     * @param configParam 实例对象
     */
    @Operation(summary = "保存或更新数据")
    @PostMapping("save")
    public void save(@RequestBody ConfigParamVO configParam) {
        configParamService.saveOrUpdate(BeanUtil.copyProperties(configParam, ConfigParam.class));
    }
    
    /** 
     * 通过主键批量删除
     *
     * @param configParamIds 主键
     */
    @Operation(summary = "通过主键批量删除")
    @PostMapping("remove-by-ids")
    public void removeByIds(@RequestBody List<String> configParamIds) {
        configParamService.removeByIds(configParamIds);
    }
}